$(function(){
	// Calling the plugin
	$('.tab-group').tabify();
	$('.tab-group-parent').tabify_parent();
			
	// 两秒后模拟点击
	setTimeout(function() {
		//IE
		if(document.all) {
			document.getElementById("grid-itemId-0").click();
		}
		//其它浏览器
		else {
			var e = document.createEvent("MouseEvents");
			e.initEvent("click", true, true);
			document.getElementById("grid-itemId-btn-0-1").dispatchEvent(e);
			$("#grid-itemId-btn-0-1").attr("border","3px solid rgba(129, 196, 131, 0.5)");
		}
	}, 100);
})

$(".textarea-item").each(function(){
	var id = this.id;
	var index = id.toString().lastIndexOf("-");
	var subIndex = id.substring(index + 1);
	
	var lenInput = $('.textarea-item' + subIndex).val().length;
	$(".textarea-item" + subIndex).keyup(function(){
		lenInput = $(this).val().length;
		if(lenInput>0 && lenInput<=300){
			$('#textareaInput' + subIndex).html(lenInput);
			$('.grid-item-btn-reply').attr('disabled',false);
			$('.grid-item-btn-reply').click(function(){
				
			});
		}else{
			$('.grid-item-btn-reply').attr('disabled',true);
		}
	});
});


$('.VivaTimeline').vivaTimeline({
	carousel: true,
	carouselTime: 3000
});
$(".grid__item").each(function(){
	var id = this.id;
	var index = id.toString().lastIndexOf("-");
	var subIndex = id.substring(index + 1);
	
	//report
	$("#grid-itemId-btn-" + subIndex + "-0").click(function(){
		$(".grid__content").each(function(){
			var contentid = this.id;
			var cIndex = contentid.toString().lastIndexOf("-");
			var subContentIndex = contentid.substring(cIndex + 1);
			$("#div-content-" + subContentIndex).attr("style", "display: none;");
		});		
		
		
		$(".grid__content__report").each(function(){
			// alert("report: "+ subIndex);
			var contentid = this.id;
			var cIndex = contentid.toString().lastIndexOf("-");
			var subContentIndex = contentid.substring(cIndex + 1);
			if(subIndex == subContentIndex){
				$("#div-content-report-" + subIndex).removeAttr("style");
			}else{
				$("#div-content-report-" + subContentIndex).attr("style", "display: none;");
			}
		});		
	});
			
	//Escalation
	$("#grid-itemId-btn-" + subIndex + "-1").click(function(){
		$(".grid__content__report").each(function(){
			var contentid = this.id;
			var cIndex = contentid.toString().lastIndexOf("-");
			var subContentIndex = contentid.substring(cIndex + 1);
			$("#div-content-report-" + subContentIndex).attr("style", "display: none;");
		});		
		$(".grid__content__org-chart").each(function(){
			var contentid = this.id;
			var cIndex = contentid.toString().lastIndexOf("-");
			var subContentIndex = contentid.substring(cIndex + 1);
			$("#div-content-report-" + subContentIndex).attr("style", "display: none;");
		});		
		
		$(".grid__content").each(function(){
			var contentid = this.id;
			var cIndex = contentid.toString().lastIndexOf("-");
			var subContentIndex = contentid.substring(cIndex + 1);
			if(subIndex == subContentIndex){
				$("#div-content-" + subIndex).removeAttr("style");
			}else{
				$("#div-content-" + subContentIndex).attr("style", "display: none;");
			}
		});		
	});
	
	//Org-Chart
	$("#grid-itemId-btn-" + subIndex + "-2").click(function(){
		$(".grid__content").each(function(){
			var contentid = this.id;
			var cIndex = contentid.toString().lastIndexOf("-");
			var subContentIndex = contentid.substring(cIndex + 1);
			$("#div-content-" + subContentIndex).attr("style", "display: none;");
		});		
		$(".grid__content__report").each(function(){
			var contentid = this.id;
			var cIndex = contentid.toString().lastIndexOf("-");
			var subContentIndex = contentid.substring(cIndex + 1);
			$("#div-content-report-" + subContentIndex).attr("style", "display: none;");
		});			
		
		$(".grid__content__org-chart").each(function(){
			// alert("report: "+ subIndex);
			var contentid = this.id;
			var cIndex = contentid.toString().lastIndexOf("-");
			var subContentIndex = contentid.substring(cIndex + 1);
			if(subIndex == subContentIndex){
				$("#grid__content__org-chart-" + subIndex).removeAttr("style");
			}else{
				$("#grid__content__org-chart-" + subContentIndex).attr("style", "display: none;");
			}
		});	
	});
});

$(".project-name").click(function(){
	$(".container-home-page").attr("style", "display: none;");
	$(".container-home-org_chart").removeAttr("style");
});

 $('.dropdown').hover(function () {
	    $('.dropdown-menu', this).fadeIn('fast');
	}, function () {
	    $('.dropdown-menu', this).fadeOut('fast');
});

var $select = $("#select");
var $myselect = $("#myselect");
var $tempselect = $("#tempselect");

/**
 * 初始化插件
 */
$myselect.goSelectInput({
	height: 36,
	width: 100
});

$tempselect.goSelectInput({
	height: 36,
	width: 150
});

$('#table').basictable();

/**
 * 获取两者的值
 */
// $("#get").click(function(){
	// alert("原生select的值为" + $select.val() + ",选中文本为'" + $select.find("option:selected").text() + "'");
	// alert("插件效果的select的值为" + $myselect.val() + ",选中文本为'" + $myselect.find("option:selected").text() + "'");
// });

// just add effect to elements
Array.prototype.forEach.call(document.querySelectorAll('[data-ripple]'), function(element){
	// find all elements and attach effect
	new RippleEffect(element); // element is instance of javascript element node
});
